home *** CD-ROM | disk | FTP | other *** search
- /*
- * The original copyright owners of the accompanying source code files have
- * agreed to place such code into the public domain. Accordingly, anyone
- * who receives or obtains a copy of such source code is freely entitled to
- * reproduce, use and otherwise exploit such code (including the right to
- * make derivative works), at his/her own risk and expense, without any
- * obligation or liability to the original copyright owners.
- *
- * We would appreciate (but do not require) that the following message be
- * included in any derivative works:
- *
- * "Portions of this program were developed by Peter Broadwell, Rob Myers
- * and Robin Schaufler while working in Silicon Valley."
- *
- * The accompanying source code files and related documentation materials
- * are distributed on an "AS IS" basis, without any warranties or
- * guarantees of any kind. All implied warranties, including the implied
- * warranties of merchantability and of fitness for any particular purpose,
- * are expressly disclaimed.
- */
- #include <stdio.h>
- #include "class.h"
-
- #define max(a,b) (a < b ? b : a)
-
- #ifdef MALDEBUG
- #define Bzero(a,b) { char *q=(a), *r=(b); \
- if(maldbug) printf("bzeroing(0x%x,0x%x)\n",q,r); \
- bzero(q,r);}
- #else
- #define Bzero(a,b) bzero(a,b)
- #endif /* MALDEBUG */
-
- extern char *gfmalloc();
- extern int maldbug;
-
- static fcnTable eot = {EOTABLE};
-
- static classFcn *
- expand(maxSelector, curClass)
- int *maxSelector;
- class *curClass;
- {
- fcnTable *entry = NULL;
- classFcn *classFcns = NULL;
-
- if(curClass == NULL) {
- fprintf(stderr,"Expand: expand called with null curClass");
- return classFcns;
- }
- if(maxSelector == NULL) {
- fprintf(stderr,"Expand: expand called with null maxSelector");
- return classFcns;
- }
- /* update maxSelector from curClass->fcnTable */
- for(entry = curClass->fcnTable;
- entry && bcmp(entry, &eot, sizeof(fcnTable)) != 0 /* unequal */;
- entry++)
- {
- *maxSelector = (int)max((*maxSelector), entry->selector);
- }
- /* get expanded classFcns so far */
- if(curClass->super) {
- classFcns = expand(maxSelector, curClass->super);
- } else if(*maxSelector >= 0) {
- if (classFcns = (classFcn *)gfmalloc((unsigned)(++(*maxSelector))*4)) {
- #ifdef MALDEBUG
- if(*(char *)classFcns) {
- printf("expand: onto non empty gfmalloc 0x%x\n",classFcns);
- }
- #endif /* MALDEBUG */
- Bzero(classFcns, (unsigned)(*maxSelector)*4);
- }
- else {
- fprintf(stderr,
- "Expand: insufficient memory for class %x\n", curClass);
- return NULL;
- }
- }
- if(classFcns == NULL) {
- return classFcns;
- }
- /* fill in classFcns */
- for(entry = curClass->fcnTable;
- entry && bcmp(entry, &eot, sizeof(fcnTable)) != 0 /* unequal */;
- entry++)
- {
- classFcns[entry->selector] = entry->function;
- }
- return classFcns;
- } /* expand */
-
- /*
- * Expand a inst's classFcns from its class list.
- * return address of expanded inst.
- */
- inst *
- Expand(obj)
- inst *obj;
- {
- classFcn *expand();
-
- if(obj == NULL) {
- return NULL;
- }
- if(obj->classFcns) {
- return obj;
- }
- obj->nFcns = -1;
- obj->classFcns = expand(&obj->nFcns, obj->myClass);
- return obj;
- } /* Expand */
-
-